package base.common;

public class Test1String {

	public static void main(String[] args) {
		System.out.println("====String====");
		String s = "A,B,C";
		System.out.println("字符串s:" + s);
		System.out.println("转小写：" + s.toLowerCase());
		System.out.println("转大写：" + s.toUpperCase());
		System.out.println("替换B变成S：" + s.replace("B", "S"));
		System.out.println("逗号分隔字符串：" + GetArrStr(s.split(",")));
	}
	
	// 使用StringBuffer
	public static String GetArrStr(String[] arr) {
		StringBuffer sb = new StringBuffer();
		sb.append("[");
		int i = -1;
		for(String s : arr) {
			i += 1;
			// 三目运算符的使用
			String separator = i == arr.length - 1 ? "" : ","; 
			sb.append(s + separator);
		}
		sb.append("]");
		return sb.toString();
	}
}
